/*

    random.h - definition of the random class
    Author Julio Agustin Barrera Mendoza
    Copyright (C) 2009 CINVESTAV-IPN.

    This program is free software; you can redistribute it and/or modify it 
    under the terms of the GNU General Public License as published by 
    the Free Software Foundation; either version 2 of the License, 
    or (at your option) any later version.

    This program is distributed in the hope that it will be useful, 
    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
    General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to 
    the Free Software Foundation, Inc., 59 Temple Place, 
    Suite 330, Boston, MA 02111-1307 USA

*/

#ifndef RANDOM_H
#define RANDOM_H

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>

#define DSFMT_MEXP 19937

#include "dSFMT/dSFMT.h"

using namespace std;

// ------------------------------------------------------------------
// CLASS Random
// ------------------------------------------------------------------

class Random
{
  public:
    Random();
    ~Random();

    void useRand(void);
    void useRandom(void);
    void useDrand48(void);
    void useMt(void);
    void setSeedSource(const string &source, const string &filename = "seeds.txt");

    const string &SeedSource(void) const {return seedSource;}
    const string &Driver(void) const {return driver;}
    unsigned int seedsLeft(void) {return seeds.size();}

    void loadSeeds(const string &filename);
    void dumpSeeds(const string &filename);

    void seed(void);
    long double Uniform(void);
    long double Normal(long double mean, long double standardDeviation);
    unsigned int Integer(void);

  private:
    string driver;
    string seedSource;
    string seedFilename;
    dsfmt_t dsfmt;
    int32_t state;
    vector<uint32_t> seeds;

    void seedFromFile(const string &filename);
};

#endif
